package com.wkbb.basic.controller.manage;

import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement;
import com.github.pagehelper.PageInfo;
import com.wkbb.basic.config.BasicConfig;
import com.wkbb.basic.feign.DoorFeignService;
import com.wkbb.basic.model.Agent;
import com.wkbb.basic.model.Organization;
import com.wkbb.basic.model.OrganizationWebank;
import com.wkbb.basic.service.OrganizationService;
import com.wkbb.basic.service.OrganizationWebankService;
import com.wkbb.basic.service.WebankUtilService;
import com.wkbb.basic.thread.SynOrgAccessInitTask;
import com.wkbb.basic.utils.WebankUtil;
import com.wkbb.common.base.BaseController;
import com.wkbb.common.config.ServiceConfig;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.OrgTypeDto;
import com.wkbb.common.dto.basic.OrganizationDto;
import com.wkbb.common.dto.basic.UserDto;
import com.wkbb.common.enums.*;
import com.wkbb.common.handler.JsonUtil;
import com.wkbb.common.utils.BeanUtil;
import com.wkbb.common.utils.JavaBeanUtil;
import com.wkbb.common.utils.StringUtil;
import com.wkbb.common.utils.ThreadPoolUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.*;

/**
 * @author Lilin
 */
@RestController
@Api(description = "组织管理(后台管理)")
@RequestMapping("/basic/{apiVersion}/organization/manage")
@Slf4j
public class OrganizationManageController extends BaseController {

    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private DoorFeignService doorFeignService;

    @Autowired
    private WebankUtilService webankUtilService;

    @Autowired
    private OrganizationWebankService organizationWebankService;

    @Autowired
    private ServiceConfig serviceConfig;

    @ApiOperation(value = "查询代理商机构分页列表")
    @RequestMapping(value = "getAgentListByPage", method = RequestMethod.GET)
    public ResultDTO<PageInfo<Agent>> getAgentListByPage(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "所在区域ID", required = false) @RequestParam(name = "areaId", required = false) Integer areaId,
            @ApiParam(value = "组织名称", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "联系人姓名", required = false) @RequestParam(name = "contactName", required = false) String contactName,
            @ApiParam(value = "联系人电话", required = false) @RequestParam(name = "contactPhone", required = false) String contactPhone,
            @ApiParam(value = "状态", required = false) @RequestParam(name = "status", required = false) Boolean status,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            Map<String, Object> params = new HashMap<>(7);
            //不是管理员 查询当前机构下的列表
            if (!isSuperAdmin(userDto)){
                if (userDto.getServiceAreaIds() == null)
                    return new ResultDTO<>(ErrorCode.ROLE_PERMISSION_ERROR);
                params.put("serviceAreaIds",userDto.getServiceAreaIds());
            }
            if (!StringUtil.isNullOrBlank(orgName)) params.put("orgName", orgName);
            if (!StringUtil.isNullOrBlank(contactName)) params.put("contactName", contactName);
            if (!StringUtil.isNullOrBlank(contactPhone)) params.put("contactPhone", contactPhone);
            params.put("status", status);
            params.put("orgType", 2);
            params.put("areaId", areaId);
            return new ResultDTO<>(organizationService.getAgentListByPage(params, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********OrganizationManageController.page******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询代理商机构详情")
    @RequestMapping(value = "getAgent", method = RequestMethod.GET)
    public ResultDTO<Agent> getAgent(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "代理商ID", required = false) @RequestParam(name = "id", required = false) Integer id) {
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            return new ResultDTO<>(organizationService.getAgentById(id));
        } catch (Exception e) {
            log.error("***********OrganizationManageController.page******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增代理商机构",notes = "{\"contactPhone\":\"13148861314\",\"contactName\":\"联系人\",\"name\":\"圣诞节弗兰克\",\"logoImg\":null,\"provinceId\":19,\"province\":\"广东\",\"cityId\":1607,\"city\":\"深圳市\",\"areaId\":3638,\"area\":\"罗湖区\",\"address\":\"罗湖111111号\",\"createBy\":null,\"account\":\"test1234\",\"password\":\"123456\",\"organizationCode\":\"A1234\",\"contactEmail\":\"email@qq.com\",\"introduce\":\"简介简介\",\"serviceProvinceId\":19,\"serviceCityId\":1607,\"serviceAreaIds\":\"3638,3639\"}")
    @RequestMapping(value = "insertAgent", method = RequestMethod.POST)
    public ResultDTO<Long> insertAgent(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "详情", required = true)@Valid @RequestBody Agent data) {
        log.info("***********OrganizationManageController.putAgent******apiVersion:{},organization:{}", apiVersion, JsonUtil.objectToJson(data));
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        if (!isSuperAdmin(userDto)){
            return new ResultDTO<>(ErrorCode.ROLE_PERMISSION_ERROR);
        }
        try {
            data.setCreateBy(userDto.getName());
            return organizationService.insertAgent(data);
        } catch (Exception e) {
            log.error("***********OrganizationManageController.add******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增组织")
    @RequestMapping(method = RequestMethod.POST)
    public ResultDTO<Long> add(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织详情", required = true) @RequestBody Organization organization) {
        log.info("***********OrganizationManageController.add******apiVersion:{},organization:{}", apiVersion, organization);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (checkData(organization)) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            if(null==organization.getParentId())
            {
                organization.setParentId(0L);
            }

            if(null==organization.getTypeSet())
            {
                organization.setTypeSet(TypeSetEnum.STATE_RUN.getValue());
            }

            if(null==organization.getOrigin())
            {
                organization.setOrigin(OriginTypeEnum.SELF_SUPPORT.getValue());
            }

            organization.setCreateBy(userDto.getName());
            organization.setUpdateBy(userDto.getName());
            return organizationService.insertOrganization(organization);

        } catch (Exception e) {
            log.error("***********OrganizationManageController.add******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 检查组织信息
     *
     * @param organization 组织信息
     * @return 是否未通过检查
     */
    private boolean checkData(Organization organization) {
        return organization.getOrgType() == null || OrganizationTypeEnum.getDesc(organization.getOrgType()) == null || StringUtil.isNullOrBlank(organization.getName());
    }

    @ApiOperation(value = "更新组织")
    @RequestMapping(method = RequestMethod.PUT)
    public ResultDTO<Long> update(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织详情", required = true) @RequestBody Organization organization) {

        log.info("***********OrganizationManageController.update******apiVersion:{},organization:{}", apiVersion, organization);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        if (checkData(organization) || organization.getId() == null || organization.getId() == 0) {
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }

        try {
            organization.setUpdateBy(userDto.getName());
            ResultDTO resultDto = organizationService.update(organization, true);
            if(!resultDto.isSuccess()){
                return resultDto;
            }
            return new ResultDTO<>(organization.getId());
        } catch (Exception e) {
            log.error("***********OrganizationManageController.update******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "更新组织状态")
    @RequestMapping(value = "/updateStatus", method = RequestMethod.PUT)
    public ResultDTO<Long> updateStatus(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织详情", required = true) @RequestBody Organization organization) {

        log.info("***********OrganizationManageController.updateStatus******apiVersion:{},orgId:{},status:{}", apiVersion, organization.getId(), organization.getStatus());
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (organization.getId() == null || organization.getId() == 0
                    || organization.getStatus() == null) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            organization.setUpdateBy(userDto.getName());
            organizationService.update(organization);
            return new ResultDTO<>(organization.getId());
        } catch (Exception e) {
            log.error("***********OrganizationManageController.updateStatus******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询组织详情")
    @RequestMapping(value = "info", method = RequestMethod.GET)
    public ResultDTO<OrganizationDto> info(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = true) @RequestParam(name = "id", required = true) Long id) {

        log.info("***********OrganizationManageController.info******apiVersion:{},id:{}", apiVersion, id);

        try {
            return new ResultDTO<>(organizationService.getInfo(id));
        } catch (Exception e) {
            log.error("***********OrganizationManageController.info******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询组织列表")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ResultDTO<List<OrganizationDto>> list(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织类型(1微看 2代理商 3机关 4集团 5幼儿园 6小学 7中职 8中学 9高职 10本科 11培训学校)", required = false, defaultValue = "1") @RequestParam(name = "orgType", required = false) Integer orgType,
            @ApiParam(value = "组织名称", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "联系人姓名", required = false) @RequestParam(name = "masterName", required = false) String masterName,
            @ApiParam(value = "联系人电话", required = false) @RequestParam(name = "masterPhone", required = false) String masterPhone,
            @ApiParam(value = "状态", required = false) @RequestParam(name = "status", required = false) Boolean status,
            @ApiParam(value = "集团园ID", required = false) @RequestParam(name = "parentId", required = false) Long parentId) {
        log.info("***********OrganizationManageController.list******apiVersion:{},orgType:{}, orgName:{}, masterName:{}," +
                        " masterPhone:{}, status:{}, agentId:{},parentId:{}", apiVersion, orgType, orgName, masterName,
                masterPhone, status, parentId);

        try {
            Map<String, Object> params = new HashMap<>(6);
            if (orgType != null && orgType != 0) {
                params.put("orgType", orgType);
            }
            if (!StringUtil.isNullOrBlank(orgName)) {
                params.put("orgName", orgName);
            }
            if (!StringUtil.isNullOrBlank(masterName)) {
                params.put("masterName", masterName);
            }
            if (!StringUtil.isNullOrBlank(masterPhone)) {
                params.put("masterPhone", masterPhone);
            }
            if (status != null) {
                params.put("status", status ? 1 : 0);
            }
            if (parentId != null) {
                params.put("parentId", parentId);
            }

            UserDto userDto = getUserByLogin();
            //判断是否是代理商
            OrganizationDto organizationDto = super.getOrgByUser(userDto);
            if (OrganizationTypeEnum.AGENT.getValue().equals(organizationDto.getOrgType())) {
                params.put("agentId", organizationDto.getId());
            }

            return new ResultDTO<>(organizationService.getList(params));
        } catch (Exception e) {
            log.error("***********OrganizationManageController.list******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询统计学校数量(启用、禁用数量)")
    @RequestMapping(value = "getOrganizationCount", method = RequestMethod.GET)
    public ResultDTO<Map<String, Object>> getOrganizationCount(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion) {
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }
        try {
            return new ResultDTO<>(organizationService.getOrganizationCount());
        } catch (Exception e) {
            log.error("***********ClassInfoManageController.page******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询学校分页列表")
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public ResultDTO<PageInfo<OrganizationDto>> page(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织类型(1微看 2代理商 3机关 4集团 5幼儿园 6小学 7中职 8中学 9高职 10本科 11培训学校)", required = false, defaultValue = "1") @RequestParam(name = "orgType", required = false) Integer orgType,
            @ApiParam(value = "所在区域ID", required = false) @RequestParam(name = "areaId", required = false) Integer areaId,
            @ApiParam(value = "组织名称", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "性质(1公办 2民办 3合办)", required = false) @RequestParam(name = "typeSet", required = false) String typeSet,
            @ApiParam(value = "联系人姓名", required = false) @RequestParam(name = "contactName", required = false) String contactName,
            @ApiParam(value = "联系人电话", required = false) @RequestParam(name = "contactPhone", required = false) String contactPhone,
            @ApiParam(value = "状态", required = false) @RequestParam(name = "status", required = false) Boolean status,
            @ApiParam(value = "集团园ID", required = false) @RequestParam(name = "parentId", required = false) Long parentId,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        log.info("***********OrganizationManageController.page******apiVersion:{},parentId:{}", apiVersion, parentId);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {

            Map<String, Object> params = new HashMap<>(7);
            //不是管理员 查询当前机构下的列表
            if (!isSuperAdmin(userDto)){
                if (userDto.getServiceAreaIds() == null)
                    return new ResultDTO<>(ErrorCode.ROLE_PERMISSION_ERROR);
                params.put("serviceAreaIds",userDto.getServiceAreaIds());
            }
            if (!StringUtil.isNullOrBlank(orgName)) {
                params.put("orgName", orgName);
            }
            if (!StringUtil.isNullOrBlank(contactName)) {
                params.put("contactName", contactName);
            }
            if (!StringUtil.isNullOrBlank(contactPhone)) {
                params.put("contactPhone", contactPhone);
            }
            if (status != null) {
                params.put("status", status ? 1 : 0);
            }
            params.put("parentId", parentId);
            if (orgType != null && orgType != 0) {
                params.put("orgType", orgType);
            }
            params.put("areaId", areaId);
            params.put("typeSet", typeSet);
            return new ResultDTO<>(organizationService.getPage(params, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********OrganizationManageController.page******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "根据组织类型查询组织信息接口")
    @RequestMapping(value = "/getOrgByType", method = RequestMethod.GET)
    public ResultDTO<List<Organization>> getOrgByType(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织类型(1微看 2代理商 3机关 4集团 5幼儿园 6小学 7中职 8初中 9高中 10高职 11本科 12培训学校)", required = false) @RequestParam(name = "orgType", required = false) Integer orgType) {

        log.info("***********OrganizationManageController.getOrgByType******apiVersion:{},orgType:{}", apiVersion, orgType);
        try {

            UserDto userDto = getUserByLogin();
            if (userDto == null) {
                return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
            }

            if (StringUtils.isEmpty(orgType)) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }
            List<Organization> orgList = new ArrayList<Organization>();
            Map<String, Object> params = new HashMap<>(1);
            //判断是否是代理商
            int roleType = getRoleTypeByUser(userDto);
            if (orgType != null && orgType != 0) {
                params.put("orgType", orgType);
            }
            if (SysRoleTypeEnum.SUPER_ADMIN.getValue() != roleType) {
                OrganizationDto organizationDto = super.getOrgByUser(userDto);
                if(OrganizationTypeEnum.AGENT.getValue().intValue()==organizationDto.getOrgType()) {
                    //如果是代理商，根据parentid查其下代理商，否则查学校
                    if(OrganizationTypeEnum.AGENT.getValue().intValue()==orgType)
                    {
                        //添加本代理商
                        Organization organization = new Organization();
                        BeanUtils.copyProperties(organizationDto,organization);
                        orgList.add(organization);

                        params.put("parentId",organizationDto.getId());
                        List<Organization> list = organizationService.getListByMapParams(params);
                        orgList.addAll(list);
                        organizationService.recursiveOrganization(orgList,orgType,list);

                        return new ResultDTO<List<Organization>>(orgList);
                    }
                    else {
                        params.put("agentId", organizationDto.getId());
                    }
                }
                else if(OrganizationTypeEnum.CONGLOMERATE.getValue().intValue()==organizationDto.getOrgType()) {
                    params.put("conglomerateId", organizationDto.getId());
                }
                else if(OrganizationTypeEnum.EDUCATION.getValue().intValue()==organizationDto.getOrgType()) {
                    //如果是教育局，根据parentid查其下教育局，否则查学校
                    if(OrganizationTypeEnum.EDUCATION.getValue().intValue()==orgType)
                    {
                        return new ResultDTO<List<Organization>>(organizationService.getEducationList(orgType,organizationDto));
                    }
                    else {
                        params.put("educationId", organizationDto.getId());
                    }
                }
                else
                {
                    //学校查询自己
                    if(OrganizationTypeEnum.WK.getValue().intValue()!=organizationDto.getOrgType()) {
                        params.put("id", userDto.getId());
                    }
                }
            }
            List<Organization> organizationList = organizationService.getListByMapParams(params);
            orgList.addAll(organizationList);

            return new ResultDTO<List<Organization>>(orgList);

        } catch (Exception e) {
            log.error("***********OrganizationManageController.getOrgByType******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }



    //一个查询接口
    @ApiOperation(value = "查询组织分页列表")
    @RequestMapping(value = "getOrgListByPage", method = RequestMethod.GET)
    public ResultDTO<Map<String,Object>> getOrgListByPage(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织类型(1微看 2代理商 3机关 4集团 5幼儿园 6小学 7中职 8初中 9高中 10高职 11本科 12培训学校)", required = true) @RequestParam(name = "orgType", required = true) Integer orgType,
            @ApiParam(value = "搜索(模糊搜索名称、负责人姓名、手机号)", required = false) @RequestParam(name = "search", required = false) String search,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        log.info("***********OrganizationManageController.getOrgListByPage******apiVersion:{},parentId:{}", apiVersion);

        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            OrganizationDto organizationDto = super.getOrgByUser(userDto);

            //-- 如果是代理商，则获取当前代理商下面的代理商
            Map<String, Object> params = new HashMap<>(3);
            if (!StringUtil.isNullOrBlank(search)) {
                params.put("search", search);
            }

            if (orgType != null && orgType != 0) {
                params.put("orgType", orgType);
            }

            //-- 如果是超管,则获取所有的代理商
            Integer userOrgType = organizationDto.getOrgType();

            //代理商
            if(userOrgType == OrganizationTypeEnum.AGENT.getValue().intValue()){
                Long parentId = organizationDto.getId();
                params.put("parentId",parentId);
            }

            //教育局
            if(userOrgType == OrganizationTypeEnum.EDUCATION.getValue().intValue()){
                List<Organization> orgList = organizationService.getEducationList(orgType,organizationDto);
                if(orgList.size()==0) {
                    params.put("parentId", organizationDto.getId());
                }
                else
                {
                    params.put("parentIds", orgList);
                }
            }

            PageInfo<OrganizationDto> orgList = organizationService.getOrgListByPage(params, pageNo, pageSize);

            Map<String,Object> resultMap = new HashMap<>(5);

            //代理商数量
            resultMap.put("agentCount",0);
            //拓展学校数量
            resultMap.put("schoolCount",0);
            //学生总人数
            resultMap.put("studentCount",0);
            //家长总人数
            resultMap.put("parentsCount",0);
            //代理商列表
            resultMap.put("orgList",orgList);

            return new ResultDTO<Map<String,Object>>(resultMap);

        } catch (Exception e) {
            log.error("***********OrganizationManageController.getOrgListByPage******", e);
            return new ResultDTO<Map<String,Object>>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "根据代理商查询学校信息接口")
    @RequestMapping(value = "/getOrgByAgent", method = RequestMethod.GET)
    public ResultDTO<List<Organization>> getOrgByAgent(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "代理商ID", required = true) @RequestParam(name = "agentId", required = true) Long agentId) {

        log.info("***********OrganizationManageController.getOrgByAgent******apiVersion:{},agentId:{}", apiVersion, agentId);
        try {

            UserDto userDto = getUserByLogin();
            if (userDto == null) {
                return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
            }

            if (null == agentId) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            Map<String, Object> params = new HashMap<String, Object>();
            if(!(getUserIsSuper(userDto)&&agentId==0)) {
                params.put("agentId", agentId);
            }

            List<Organization> organizationList = organizationService.getListByMapParams(params);

            return new ResultDTO<List<Organization>>(organizationList);
        } catch (Exception e) {
            log.error("***********OrganizationManageController.getOrgByAgent******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

}
